package com.xca.rxjavademo.utils;

public class WeatherBackgroundUtils {
    public static String getDirection(String wind_direction){
        String direction = "";
        switch (wind_direction){
            case "N":
                direction = "北风";
                break;
            case "NE":
                direction = "东北风";
                break;
            case "E":
                direction = "东风";
                break;
            case "SE":
                direction = "东南风";
                break;
            case "S":
                direction = "南风";
                break;
            case "SW":
                direction = "西南风";
            case "W":
                direction = "西风";
                break;
            case "NW":
                direction = "西北风";
                break;
            default:
                direction = "无风向";
        }
        return direction;
    }

    public static String getBackgroundUrl(String weather){
        String weatherType = extractWeatherType(weather);
        String url = "";
        switch (weatherType){
            case "晴":
                url = "https://img.bizhiduo.cn/images/q9tjtj-small.jpg";
                return url;
            case "阴":
                url = "https://img.bizhiduo.cn/images/nhlbas-small.jpg";
                return url;
            case "多云":
                url = "https://img.bizhiduo.cn/images/pjw73k-small.jpg";
                return url;
            case "霾":
                url = "https://img.bizhiduo.cn/images/h0a7ra-small.jpg" ;
                return url;
            case "雨":
                url = "https://img.bizhiduo.cn/images/xsyumd-small.jpg" ;
                return url;
            case "雪":
                url = "https://img.bizhiduo.cn/images/23y5gf-small.jpg" ;
                return url;
            case "风":
                url = "https://img.bizhiduo.cn/images/1t1a7d-small.jpg" ;
                return url;
            case "雾":
                url = "https://img.bizhiduo.cn/images/i5vibr-small.jpg" ;
                return url;
        }
        return url;
    }


    private static String extractWeatherType(String description) {
        description = description.trim();

        // 匹配规则，这里使用正则表达式
        String finedPattern = "(?i).*晴.*";
        String cloudPattern = "(?i).*多云.*";
        String fogPattern = "(?i).*雾.*";
        String hazyPattern = "(?i).*霾.*";
        String wingPattern = "(?i).*风.*";
        String rainPattern = "(?i).*雨.*"; // 匹配包含“雨”的任何描述
        String snowPattern = "(?i).*雪.*"; // 匹配包含“雪”的任何描述
        String cloudyPattern = "(?i).*阴.*";

        if (description.matches(rainPattern)) {
            return "雨";
        } else if (description.matches(snowPattern)) {
            return "雪";
        }else if (description.matches(finedPattern)) {
            return "晴";
        }
        else if (description.matches(cloudPattern)) {
            return "多云";
        }
        else if (description.matches(hazyPattern)) {
            return "霾";
        }
        else if (description.matches(wingPattern)) {
            return "风";
        } else if (description.matches(fogPattern)) {
            return "雾";
        } else if (description.matches(cloudyPattern)) {
            return "阴";
        } else {
            // 默认处理逻辑
            return description.isEmpty() ? "" : "未知";
        }
    }
}
